﻿using FastCloud.Base.Config;
using FastCloud.Base.Desgin;
using FastCloud.ORG.Entity;
using FastUtil.Data;
using System;
using System.Collections.Generic;
using System.Text;

namespace FastCloud.ORG.DB
{
    public class DB_Module : BaseDBML<Frame_Module>
    {
        public override void Insert(Frame_Module Entity)
        {
            if (string.IsNullOrEmpty(Entity.ModuleGuid))
            {
                Entity.ModuleGuid = GenerateUtil.GenerateUnitGuid();
            }
            Entity.IsPublic = (int)Base.Enum.ORG.IsPublic.不完全公开;
            Entity.AddDate = DateTime.Now;
            Entity.ModuleCode = CloudUtil.CreateTableFieldCodeValue("Frame_Module", "ModuleGuid", "ModuleCode", "ParentModuleGuid", Entity.ParentModuleGuid);
            base.Insert(Entity);
        }

        public override void UpdateByID(Frame_Module Entity)
        {
            Frame_Module DBEntity = SelectOne(Entity.ModuleGuid);
            if (Entity.ParentModuleGuid != DBEntity.ParentModuleGuid)
            {
                Entity.ModuleCode = CloudUtil.CreateTableFieldCodeValue("Frame_Module", "ModuleGuid", "ModuleCode", "ParentModuleGuid", Entity.ParentModuleGuid);
            }
            base.UpdateByID(Entity);
        }

        public void UpdateModulePublic(string ModuleGuid,int IsPublic)
        {
            Frame_Module Entity = SelectOne(ModuleGuid);
            Entity.IsPublic = IsPublic;
            base.UpdateByID(Entity);
        }
    }
}
